<template>
	<view class="body">
		<xk-header title="巡检抽查"></xk-header>
		<view class="list" >
			<view class="list-item header" @click="orderMore = !orderMore">
				<view>巡检单号:  XC202105190001</view>
				<image v-if="!orderMore" src="/static/up.png"></image>
				<image v-else  src="/static/down.png"></image>
			</view>
			<view v-if="orderMore" class="data-item">
				<view class="order-info">
					<view class="info-item"><view class="key">设备信息：</view>DV202105190001-压力泵</view>
					<view class="info-item"><view class="key">巡检位置：</view>1栋地下室二层</view>
					<view class="info-item"><view class="key">巡检时段：</view><text>2021-5-19 10:00 - 10:00</text></view>
				</view>
			</view>
		</view>

		<view class="list" >
			<view class="list-item header" @click="orderMore = !orderMore">
				<view>巡检记录</view>
				<image v-if="!orderMore" src="/static/up.png"></image>
				<image v-else  src="/static/down.png"></image>
			</view>
			<view v-if="orderMore" class="data-item">
				<view class="order-info">
					<view class="info-item"><view class="key">巡检人：</view>黄期</view>
					<view @click="viewDetail" class="info-item" style="justify-content: space-between;">
						<view class="key">巡检详情：</view>
						<view style="display: flex; align-items: center;">
							<text class="right-title1" style="color: #2C72FF;">查看明细</text>
							<image mode="aspectFill" class="jiantou" src="/static/jiantou.png"/>
						</view>
					</view>
					<view class="info-item"><view class="key">巡检结果：</view>正常</view>
					<view class="info-item"><view class="key">完成时间：</view>2021-05-19 11:00</view>
					<view class="info-item"><view class="key">是否超时：</view>否</view>
					<!-- <view class="info-item"><view class="key">异常描述：</view>运行频率过高</view> -->
					<view class="info-item"><view class="key"></view>
						<image-list :pics="'/static/temp/temp.jpeg'"></image-list>
					</view>
				</view>
			</view>
		</view>

		<!-- <swiper class="swiper" :style="{height: swiperHeight + 'px'}" :current="current"
		 :duration="duration" @change="swiperTab">
			<swiper-item v-for="(item, index) in optionNum" :key="index">
				<view class="swiper-item">
					<view class="swpier-item" style="margin-top: 20rpx;">
						<view class="title">
							<view>巡检明细</view>
							<view class="right-title">
								共<view style="margin: 0 6rpx;color: #2C72FF;">{{optionNum}}</view>个巡查项
							</view>
						</view>
						<view class="sub-title">{{index + 1}}/{{optionNum}} 巡查项</view>
						<view class="content">
							<text>
								出水压力（Mpa）
								标准值：0.9300000071525574Mpa
								最小值：0.8500000238418579Mpa
								最大值：1.600000023841858Mpa
							</text>
						</view>
						<view class="result-item">
							<view>巡检值：0.66Mpa</view>
						</view>
						<view class="handle-btn">
							<view>上一项</view>
							<view>下一项</view>
						</view>
					</view>
				</view>
			</swiper-item>
		</swiper> -->

		<view class="list">
			<view class="list-item header">
				<view>巡检抽查</view>
			</view>
			<view>
				<view class="list-item">
					<view>抽查意见：</view>
					<input class="input-item" type="number" v-model="formInfo.work_time" placeholder="请输入抽查意见" placeholder-class="placeholder"/>
				</view>
				<view class="list-item textarea">
					<view>备注：</view>
					<textarea v-model="formInfo.record_remark" placeholder="备注" placeholder-class="placeholder"/>
				</view>
			</view>
		</view>
		<!-- <view class="upload-img-item">
			<view class="title">上传巡查照片</view>
			<upload-image images="" @onChange="uploadImageChange"/>
		</view> -->
		<view class="common-bottom-view">
			<view class="common-btn btn-plant" @click="reportRepair">退回</view>
			<view class="common-btn" @click="doneRepair">通过</view>
		</view>
		<view class="common-zw"></view>


	</view>
</template>

<script>
	import moment from 'moment'
	export default {
		data() {
			return {
				optionNum: 4,
				swiperHeight: 400,
				data: {},
				orderMore: true,
				typeIndex: -1,
				types:[],
				playerIndex: -1,
				players:[],
				repairDate: '',
				repairTime: '',
				linkageVisible: false,
				typeValue: ['', '', '', ''],
				typeMap: {},
				defaultDate: moment().format('YYYY-MM-DD HH:mm'),
				formInfo: {
				    repair_id: "",	// 服务报修申请id
				    repair_type_id: "",	// 维修种类id
				    finish_time: "",
				    work_time: "",	//
				    repair_money: "",
				    payer: "",
				    record_image: "",
				    record_remark: "",
				    isSubmit: true,
				    materials: []
				},
				notNull: {
					repair_id: "无法找到报修单号",
					repair_type_id: "请选择维修类型",
					finish_time: "请选择完成日期",
					work_time: "请输入工作时长",
					repair_money: "请输入结算金额",
					payer: "请选择支付方",
					record_remark: "请输入维修描述"
				}
			};
		},
		onLoad(options) {
			this.formInfo.repair_id = options.repairId;
			// this.getServiceRepairData()
			// this.initInfo()
		},
		onUnload(){
			uni.$off('getMateInfo')
		},
		onShow(){
			this.setSwiperHeight()
		},
		methods:{
			viewDetail(){
				uni.navigateTo({
					url: '/pages/facility-patrol/facility-patrol-result-detail'
				})
			},
			swiperTab(e) {
				this.current = parseInt(e.target.current);
				this.setSwiperHeight()
			},
			setSwiperHeight() {
				console.log('222222h')
				this.$util.getElRect('.swiper-item').then(res=>{
					console.log(res)
					this.swiperHeight = res.height;
				})

			},
			getServiceRepairData(){
				this.$api.baseData_getPmServiceRepair(this.formInfo.repair_id).then((res)=>{
					this.data = res.pmServiceRepair
				})
			},
			initInfo() {
				this.$api.baseData_getToolDataList({
					code: "PM_SERVICE_REPAIR_PAYER" + "_nostr"
				}).then(res => {
					console.warn("支付方: ", res)
					this.players = res
				})
				let types = [[],[],[],[]]
				this.$api.baseData_getBaseRepairType().then(res => {
					console.warn("维修类型: ", res)
					for (let item of res) {
						this.typeMap[item.type_id] = item.type_name
						types[item.type_level - 1].push(item)
					}
					let tt = this.initTypes(types, '', 1)
					this.types = tt
					console.log('ttt', tt)
				})
			},
			initTypes(list, pid, level){
				let child = []
				for(let item of list[level - 1]){
					if (item.type_level > 3) continue	// 最多只能三级菜单
					if(item.type_id.startsWith(pid)){
						let cc = []
						if(level < 4){
							cc = this.initTypes(list, item.type_id, level + 1)
						}
						child.push({
							value: item.type_id,
							text: item.type_name,
							children: cc
						})
					}
				}
				// if(child.length == 0 && level <= 4){
				// 	let c = Object.assign({}, pnode);
				// 	let b = null;
				// 	for(let i = level; i <= 4; i++){
				// 		b = Object.assign({}, pnode)
				// 		b.children = [c]
				// 		c = b
				// 	}
				// 	child.push(b)
				// 	console.log('tdkekek', level, b)
				// }
				return  child
			},
			typeChange(res) {
				this.formInfo.repair_type_id = res[res.length - 1]
			},
			// dateChange(e){
			// 	this.repairDate = e.detail.value
			// },
			// timeChange(e){
			// 	this.repairTime = e.detail.value
			// },
			dealTimeChange(e){
				this.formInfo.finish_time = moment(e.dt).format('YYYY-MM-DD HH:mm')
			},
			playerChange(e){
				this.playerIndex = e.detail.value;
				this.formInfo.payer = this.players[this.playerIndex].data_value
			},
			uploadImageChange(images) {
				console.warn("图片列表：", images)
				this.formInfo.record_image = images
			},
			editMate(){
				uni.$off('getMateInfo')
				uni.$on('getMateInfo', (res)=>{
					this.formInfo.materials = res
				});
				uni.navigateTo({
					url: '/pages/facility-repair/facility-repair-material?mateList=' + JSON.stringify(this.formInfo.materials)
				})
			},
			doneRepair(){
				console.warn("formInfo: ", this.formInfo)
				// if (this.repairDate && this.repairTime) {
				// 	this.formInfo.finish_time = this.repairDate + " " + this.repairTime
				// }
				for (let item in this.notNull) {
					if (!this.formInfo[item]) {
						this.$util.toast(this.notNull[item]);
						return;
					}
				}
				this.$util.confirm({
					content: "确定提交完成维修？",
					confirmText: "完成维修"
				}).then(isConfirm => {
					if (isConfirm) {
						this.$util.post({
							url: "app/pmServiceRepair/register",
							data: {
								...this.formInfo,
								work_time: parseInt(this.formInfo.work_time),
								repair_money: parseInt(this.formInfo.repair_money)
							}
						}).then(res => {
							uni.$emit('refreshHomeDataList')
							uni.$emit('refreshServiceRepair')
							uni.redirectTo({
								url: '/pages/facility-repair/facility-repair-finish?type=done'
							})
						})

					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
@import '@/common/from.scss';
</style>
